package cn.juforg.gobang;

import java.util.List;

import cn.juforg.gobang.interfaces.BasePlayerDao;

public class BasePlayer implements BasePlayerDao{
	private List<Chess> myChess;		//我下的所有棋子
	private boolean myChessFlag;           //我棋子的代号 
	private boolean mettle ;				//玩家性格
	public static final boolean activist = true;	//激进（优先进攻）
	public static final boolean conservatism = false;//保守（优先防守）
	public BasePlayer(boolean myChessFlag) {
		super();
		this.myChessFlag = myChessFlag;
	}
	public boolean getMyChessFlag() {
		return myChessFlag;
	}
	public void setMyChessFlag(boolean myChessFlag) {
		this.myChessFlag = myChessFlag;
	}
	@Override
	public boolean hasWin(Chess lastchess, boolean whoschess ,char[][] chessArray) {
		int count ;
		char playerFlag = whoschess?ChessBoard.BLACK:ChessBoard.WHITE;
		int x = lastchess.getX();
		int y = lastchess.getY();
		int n ;
		//横向
		count = 1;
		while ((x+count)<ChessBoard.maxX && (chessArray[x+count][y]==playerFlag || chessArray[x+count][y]==playerFlag+2)) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		for (n=x-1;n >= 0 && (chessArray[n][y]==playerFlag || chessArray[n][y]==playerFlag+2);n--) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		//纵向
		count =1;
		while ((y+count)<ChessBoard.maxY && (chessArray[x][y+count]==playerFlag||chessArray[x][y+count]==playerFlag+2)) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		for (n=y-1;n >= 0 && (chessArray[x][n]==playerFlag || chessArray[x][n]==playerFlag+2);n--) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		//正斜向 ‘/’
		count =1;
		while ((x+count)<ChessBoard.maxX && (y-count)>=0 && (chessArray[x+count][y-count]==playerFlag||chessArray[x+count][y-count]==playerFlag+2)) {
			count++;
			if (count>=5) {
				return true;
			}
			n++;
		}
		for (n=1;x-n >= 0 && (y+n) <ChessBoard.maxY && (chessArray[x-n][y+n]==playerFlag || chessArray[x-n][y+n]==playerFlag);n++) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		//反斜向 ‘\’
		count =1;
		while ((x-count)>=0 && (y-count)>=0 && (chessArray[x-count][y-count]==playerFlag||chessArray[x-count][y-count]==playerFlag+2)) {
			count++;
			if (count>=5) {
				return true;
			}
			n++;
		}
		for (n=1;(y+n)<ChessBoard.maxY && (x+n)<ChessBoard.maxX && (chessArray[x+n][y+n]==playerFlag || chessArray[x+n][y+n]==playerFlag+2);n++) {
			count++;
			if (count>=5) {
				return true;
			}
		}
		return false;
	}
	@Override
	public Chess run() {
		// TODO Auto-generated method stub
		return null;
	}


	
}
